package com.region.http.client.annotation.configurer;

import com.region.http.client.protector.RequestProtector;
import com.region.http.client.request.HttpExecutor;

import java.lang.annotation.*;

/**
 * @author liujieyu
 * @date 2024/8/20 14:12
 * @desciption
 */
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = {ElementType.TYPE})
@Documented
public @interface LocalConfigurer {

    /**
     * Connect Time
     *
     * @return
     */
    int connectTime() default -1;

    /**
     * The Read Time from request
     *
     * @return
     */
    int readTime() default -1;

    /**
     * The request time
     *
     * @return
     */
    int requestTime() default -1;

    /**
     * Initiating HTTP request actuator class
     * The item is in singleton mode
     *
     * @return
     */
    Class<? extends HttpExecutor> executor() default HttpExecutor.class;

    /**
     * Get the first protector configuration
     * @return
     */
    Protector[] protectors() default {};

    @Retention(RetentionPolicy.RUNTIME)
    @Target({})
    @interface Protector {

        /**
         * After the last time the protector was triggered, the service node is requested again, default 30 seconds.
         * @return
         */
        int intervalTime() default 30;

        /**
         * Specifies that the average response time exceeds the specified time, which triggers the protector. default 10000 millisecond.
         * @return
         */
        int exceedsTime() default 10000;

        /**
         * Fallback class for the specified Region Http Client interface. When the specified service is abnormal or exceeds the average response time,
         * Triggers the specified protector, the fallback must be implement the interface.
         * @return
         */
        Class<? extends RequestProtector> fallbackClass() default RequestProtector.class;
    }
}
